package rpc_netty.NacosUtils;

import org.omg.CORBA.PRIVATE_MEMBER;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ShutDownHook {
    private static final Logger logger= LoggerFactory.getLogger(ShutDownHook.class);

    private final ExecutorService threadPool= Executors.newFixedThreadPool(3);
    private static final ShutDownHook shutDownHook=new ShutDownHook();

    public static ShutDownHook getShutDownHook(){
        return shutDownHook;
    }

    public void addClearAllHook(){
        logger.info("deregidter the services after shutdown");
        Runtime.getRuntime().addShutdownHook(new Thread(()->{
            NacosUtil.clearRegistry();

            threadPool.shutdown();
        }));
    }
}
